<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="项目管理"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'name',width:80,align:'center'">项目名称</th>
				<th data-options="field:'projectCode',width:80,align:'center'">项目代号</th>
				<th data-options="field:'projectSourceName',width:60,align:'center'">项目来源</th>
				<th data-options="field:'projectReportFrequencyName',width:60,align:'center'">项目报告频度</th>
				<th data-options="field:'projectTypeName',width:60,align:'center'">项目类型</th>
				<th data-options="field:'departmentName',width:60,align:'center'">部门</th>
				<th data-options="field:'startDate',width:60,align:'center'">项目开始日期</th>
				<th data-options="field:'planFinishDate',width:60,align:'center'">计划完成日期</th>
				<th data-options="field:'actualFinishDate',width:60,align:'center'">实际完成日期</th>
				<th data-options="field:'id',width:120,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem');$('#addPlanFinishDateChangeCount').val(0);$('#addStatus').val('0001');$('#addProjectHardRate').textbox('setValue', 1.0);">新增</a>
		</div>
		<div>
			项目来源:
			<select data-options="editable: false" id = "projectSource" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projectSources }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			报告频度:
			<select data-options="editable: false" id = "projectReportFrequency" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projectReportFrequencys }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			客户:
			<select data-options="editable: false" id = "customer" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${customers }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			项目类型:
			<select data-options="editable: false" id = "projectType" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projectTypes }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			部门:
			<select data-options="editable: false" id = "department" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${departments }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			项目名称: <input class="easyui-textbox" type="text" id="name" style="width:200px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>	
	
	<div id="addItem" class="easyui-window" title="新增项目" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:950px; height:400px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editProject" style = "width:100%; height: 100%">
					<input type="hidden" name = "planFinishDateChangeCount" value="0" id="addPlanFinishDateChangeCount" >
					<input type="hidden" name="status" id="addStatus" value="0001" />
					<table width="100%" height="100%">
						<tr>
							<td width="100px" align="right">项目名称：</td>
							<td>
								<input class="easyui-textbox" name="name" style="width: 200px;" data-options="required:true" />
							</td>
							<td width="100px" align="right">项目代号：</td>
							<td>
								<input class="easyui-textbox" name="projectCode" style="width: 200px;" />
							</td>
							<td width="100px" align="right">项目来源:</td>
							<td>
								<select name = "projectSource.id"  style="width: 200px;" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectSources }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">报告频度:</td>
							<td>
								<select name = "projectReportFrequency.id" style="width: 200px;"  class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectReportFrequencys }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">客户:</td>
							<td>
								<input class="easyui-textbox" id="addCustomer" data-options="required:true" readonly="readonly" style="width: 200px;" />
								<input type="hidden" name="customer.id" id="addCustomerId" />
							</td>
							<td align="right">项目类型:</td>
							<td>
								<select name = "projectType.id"  style="width: 200px;" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectTypes }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">部门:</td>
							<td>
								<select name = "department.id" style="width: 200px;"  class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${departments }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">计划完成日期:</td>
							<td>
								<input class="easyui-datebox" name="firstPlanFinishDate" style="width: 200px;" />
							</td>
							<td align="right">计划消耗工时:</td>
							<td>
								<input class="easyui-numberbox" data-options="required:true, precision: 2" name="planConsumeWorkTime" style="width: 200px;" />
							</td>
						</tr>
						<tr>
							<td align="right">难度系数:</td>
							<td>
								<input class="easyui-numberbox" name="hardRate" id="addProjectHardRate" value="1.0" style="width: 200px;" data-options="required:true, precision: 2"/>
							</td>
							<td align="right">课题工号:</td>
							<td>
								<input class="easyui-textbox" name="projectPlanNo" style="width: 200px;" />
							</td>
							<td align="right">批次号:</td>
							<td>
								<input class="easyui-textbox" name="projectBatchNo" style="width: 200px;" />
							</td>
						</tr>
						<tr>
							<td align="right">项目描述：</td>
							<td colspan="5">
								<input class="easyui-textbox" name="projectDescription" style="width: 830px; height: 140px;" data-options="multiline:true" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
   
   <div id="editItem" class="easyui-window" title="编辑" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:950px; height:400px;padding:5px;">
       <div class="easyui-layout" data-options="fit:true">
           <div data-options="region:'center'" style="padding:10px;">
               <form id="editForm" method="post" action="editProject" style = "width:100%; height: 100%">
                   <input type="hidden" id="editId" name = "id">
                   <input type="hidden" id="editPlanFinishDateChangeCount" name = "planFinishDateChangeCount">
                   <input type="hidden" name="createDate" id="editCreateDate" />
                   <input type="hidden" name="status" id="editStatus" value="0001" />
                   <table width="100%" height="100%">
                       <tr>
                           <td width="100px" align="right">项目名称：</td>
                           <td>
                               <input class="easyui-textbox" name="name" id="editName" data-options="required:true" style="width: 200px;" />
                           </td>
                           <td width="100px" align="right">项目代号：</td>
                           <td>
                               <input class="easyui-textbox" name="projectCode" id="editProjectCode" style="width: 200px;" />
                           </td>
                           <td width="100px" align="right">项目来源:</td>
                           <td>
                               <select name = "projectSource.id"  style="width: 200px;" id="editProjectSourceId" class="easyui-combobox" data-options="required:true, editable: false">
                                   <c:forEach var="item" items="${projectSources }" >
                                       <option value = "${item.id }">${item.name }</option>
                                   </c:forEach>
                               </select>
                           </td>
                       </tr>
                       <tr>
                           <td align="right">报告频度:</td>
                           <td>
                               <select name = "projectReportFrequency.id" style="width: 200px;" id="editProjectReportFrequenceId" class="easyui-combobox" data-options="required:true, editable: false">
                                   <c:forEach var="item" items="${projectReportFrequencys }" >
                                       <option value = "${item.id }">${item.name }</option>
                                   </c:forEach>
                               </select>
                           </td>
                           <td align="right">客户:</td>
                           <td>
								<input class="easyui-textbox" id="editCustomer" data-options="required:true" readonly="readonly" style="width: 200px;" />
								<input type="hidden" name="customer.id" id="editCustomerId" />
                           </td>
                           <td align="right">项目类型:</td>
                           <td>
                               <select name = "projectType.id" id="editProjectTypeId" style="width: 200px;" class="easyui-combobox" data-options="required:true, editable: false">
                                   <c:forEach var="item" items="${projectTypes }" >
                                       <option value = "${item.id }">${item.name }</option>
                                   </c:forEach>
                               </select>
                           </td>
                       </tr>
                       <tr>
                           <td align="right">部门:</td>
                           <td>
                               <select name = "department.id" id="editDepartmentId" style="width: 200px;" class="easyui-combobox" data-options="required:true, editable: false">
                                   <c:forEach var="item" items="${departments }" >
                                       <option value = "${item.id }">${item.name }</option>
                                   </c:forEach>
                               </select>
                           </td>
                           <td align="right">计划完成日期:</td>
                           <td>
                               <input class="easyui-datebox" name="firstPlanFinishDate" id="editFirstPlanFinishDate" style="width: 200px;" />
                           </td>
							<td align="right">计划消耗工时:</td>
							<td>
								<input class="easyui-numberbox" name="planConsumeWorkTime" id="editPlanConsumeWorkTime" style="width: 200px;" data-options="required:true, precision: 2" />
							</td>
                       </tr>
                       <tr>
                           <td align="right">难度系数:</td>
                           <td>
                               <input class="easyui-numberbox" name="hardRate" id="editHardRate" style="width: 200px;" data-options="required:true, precision: 2" />
                           </td>
                           <td align="right">课题工号:</td>
                           <td>
                               <input class="easyui-textbox" name="projectPlanNo" id="editProjectPlanNo" style="width: 200px;" />
                           </td>
                           <td align="right">批次号:</td>
                           <td>
                               <input class="easyui-textbox" name="projectBatchNo" id="editProjectBatchNo" style="width: 200px;" />
                           </td>
                       </tr>
                       <tr>
                           <td align="right">项目描述：</td>
                           <td colspan="5">
                               <input class="easyui-textbox" name="projectDescription" id="editProjectDescription" style="width: 830px; height: 140px;" data-options="multiline:true" />
                           </td>
                       </tr>
                   </table>
               </form>
           </div>
           <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
               <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
               <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
           </div>
       </div>
   </div>
	
	<div id="maintainItem" class="easyui-window" title="项目维护" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:1100px; height:650px;padding:0px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:0px;">
				<iframe id="maintain" width="100%" height="100%" frameborder="0"></iframe>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#maintainItem').window('close');" style="width:80px">关闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			var content = '<a class="ctl" href="javascript:void(0)" onclick="editItem(' + val + ')">信息编辑</a>';
			content += ' <a class="ctl" href="javascript:void(0)" onclick="maintainItem(' + val + ')">项目维护</a>';
			if(row.statusCode == '0001'){
				content += ' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
			}
			return content;
		}
		function search(){
			var dg = $("#dg");
			var name = $("#name").textbox("getValue").trim();
			var projectSource = $("#projectSource").textbox("getValue").trim();
			var projectReportFrequency = $("#projectReportFrequency").textbox("getValue").trim();
			var customer = $("#customer").textbox("getValue").trim();
			var projectType = $("#projectType").textbox("getValue").trim();
			var department = $("#department").textbox("getValue").trim();
			var url = "queryProject?projectSourceId=" + projectSource + "&customerId=" + customer + "&projectReportFrequencyId=" + projectReportFrequency + "&projectTypeId=" + projectType + "&departmentId=" + department + "&name=" + name;
			dg.datagrid('reload', url);
		}
		
		function editItem(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findProject",
			  	data: params,
			  	success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
							var item = val.data;
						
				           $("#editId").val(id);
				           $("#editPlanFinishDateChangeCount").val(item.planFinishDateChangeCount);
				           $("#editCreateDate").val(item.createDate);
				           $("#editProjectSourceID").combobox("setValue", item.projectSourceID);
				           $("#editProjectReportFrequencyID").combobox("setValue", item.projectReportFrequencyID);
				           $("#editDepartmentID").combobox("setValue", item.departmentID);
				           $("#editProjectTypeID").combobox("setValue", item.projectTypeID);
				           $("#editProjectSourceID").combobox("setValue", item.projectSourceID);
				           $("#editName").textbox("setValue", item.name);
				           $("#editProjectCode").textbox("setValue", item.projectCode);
				           $("#editStartDate").textbox("setValue", item.startDate);
				           $("#editFirstPlanFinishDate").textbox("setValue", item.firstPlanFinishDate);
				           $("#editPlanFinishDate").textbox("setValue", item.planFinishDate);
				           $("#editActualFinishDate").textbox("setValue", item.actualFinishDate);
				           $("#editProjectPlanNo").textbox("setValue", item.projectPlanNo);
				           $("#editProjectBatchNo").textbox("setValue", item.projectBatchNo);
				           $("#editPlanConsumeWorkTime").textbox("setValue", item.planConsumeWorkTime);
				           $("#editActualConsumeWorktime").textbox("setValue", item.actualConsumeWorktime);
				           $("#editHardRate").textbox("setValue", item.hardRate);
				           $("#editProjectDescription").textbox("setValue", item.projectDescription);
				           $("#editCustomer").textbox("setValue", item.customerName);
				           $("#editCustomerId").val(item.customerID);
				           $("#editStatus").val(item.statusCode);
				           
				           $('#editItem').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
       }
		
		function maintainItem(id){
			var url = "editProjectDetail?id=" + id;
			$("#maintain").attr("src", url);
			$('#maintainItem').window('open');
		}
		
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的项目吗？", function(r){
				if(r){
					var params = "id=" + id;
					$.ajax({
					  	type: "GET",
					  	url: "delProject",
					  	data: params,
					  	success:function(data){
							var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '操作成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  	}
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#customerForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						bottomRight('提示', '添加成功！');
						$('#addCustomerItemWindow').window('close');
						$("#customerdg").datagrid('reload');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#addCustomer").textbox("textbox").bind("mousedown", function(){
				$('#showCustomerItemWindow').window('open');
				customerSearch();
				$("#prixId").val("add");
			});
			$("#editCustomer").textbox("textbox").bind("mousedown", function(){
				$('#showCustomerItemWindow').window('open');
				customerSearch();
				$("#prixId").val("edit");
			});

			search();
		});
		function customerSearch(){
			var name = $("#searcheCustomerName").textbox("getValue").trim();
			var url = "queryCustomer?name=" + name;
			$("#customerdg").datagrid('reload', url);
		}
		function selectCustomerItem(){
			var row = $("#customerdg").datagrid("getSelected");
			if(!row){
				bottomleft('提示', '请选择一个客户！');
				return;
			}
			var prix = $("#prixId").val();
			$("#" + prix + "CustomerId").val(row.id);
			$("#" + prix + "Customer").textbox("setValue", row.name);
			$('#showCustomerItemWindow').window('close');
		}
	</script>
	
	<div id="showCustomerItemWindow" class="easyui-window" title="选择客户" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:720px; height:337px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<input type="hidden" id="prixId" />
				<table id="customerdg" class="easyui-datagrid" style="width: 99%; height: 100%;"
					data-options="
						rownumbers:true,
						singleSelect: true,
						singleSelect:true,
						toolbar: '#customertb',
						pagination:true
					">
					<thead>
						<tr>
							<th data-options="field: 'id', checkbox: true"></th>
							<th data-options="field:'name',width:200,align:'center'">客户名称</th>
							<th data-options="field:'code',width:200,align:'center'">客户编码</th>
							<th data-options="field:'address',width:200,align:'center'">地址</th>
						</tr>
					</thead>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="selectCustomerItem()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#showCustomerItemWindow').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>

	<div id="customertb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('customerForm', 'addCustomerItemWindow')">新增</a>
		</div>
		<div>
			客户名称: <input class="easyui-textbox" type="text" id="searcheCustomerName" style="width:240px;height:25px;">
			<a href="javascript:customerSearch()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>

	<div id="addCustomerItemWindow" class="easyui-window" title="新增客户信息" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:560px; height:300px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="customerForm" method="post" action="editCustomer" style = "width:100%; height: 100%">
					<table width="100%" height="100%">
						<tr>
							<td width="100px;" align="right">客户名称：</td>
							<td>
								<input class="easyui-textbox" name="name" data-options="required:true" style="width: 420px;" />
							</td>
						</tr>
						<tr>
							<td width="100px;" align="right">客户编码：</td>
							<td>
								<input class="easyui-textbox" name="code" style="width: 420px;" />
							</td>
						</tr>
						<tr>
							<td align="right">客户地址：</td>
							<td>
								<input class="easyui-textbox" data-options="multiline:true" style="width: 420px; height: 60px;" name="address">
							</td>
						</tr>
						<tr>
							<td align="right">备注：</td>
							<td>
								<input class="easyui-textbox" data-options="multiline:true" style="width: 420px; height: 60px;" name="remark">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#customerForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addCustomerItemWindow').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	 
</body>
</html>